<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>大钞市·每天领钱</title>
    
    <link rel="stylesheet" href="css/index.css" />
	<link rel="stylesheet" href="css/toast.css" />
	<script src="js/toast.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
     <script src="js/config.js"></script>
    
</head>
<body>

	<header>
		<img class="refresh" src="./images/refresh.png" alt="" />
	</header>


	<!--绑定手机弹窗-->
	<div class="tan">
		<div class="meng">

			<div class="phone">
				<label for="number">手机号：</label>
				<input id="number" type="number" placeholder="手机号"  onfocus="this.placeholder=''"/>
			</div>

			<div class="password">
				<div class="phone1">
					<label for="code">验证码：</label>
					<input id="code" type="number" placeholder="验证码" onfocus="this.placeholder=''" onblur="this.placeholder='验证码'"/>
				</div>

				<div class="yanzheng">
					<span>发送验证码</span>
				</div>

				<dic class="close">
					<img src="./images/grey-close.png" alt="" />
				</dic>

			</div>

			<div class="btn">
				<span>确定</span>
			</div>

		</div>
	</div>



	<div class="zhushou">
		<div class="zhushou-content">
			<div class="app-icon">
				<div class="icon-img">
					<img src="./images/app-icon.png" alt="" />
				</div>
			</div>

			<div class="icon-title">需启动助手才能开始试玩</div>

			<button class="app-btn"><a onclick="checkLogin('')">下载</a></button>

		</div>

	</div>




	<div class="container">
		<div class="top">
			<div class="box">
				<div class="avatar">
			    	<img src="./images/avatar.png" alt="" />
			    	<span id="user"></span>
		    	</div>
		    
		    	<div class="right">
		    		<div class="bgleft">
		    			<div class="icon">
			    		<img src="./images/1.png" alt="" />
				    	</div>
			    	
				    	<div class="dengji">
				    		LV1
				    	</div>
		    		</div>
		    		
		    		<div class="bgright">

		    			<div class="ling" id="bangding">绑手机</div>
		    		</div>
			    	
		    	
		    		
		    	</div>
				
				
			</div>
			
			<div class="line"></div>
			<div class="box1">
				<div class="left">
					<div class="tixian">
						<span>我的零钱</span>
						<span>提现></span>
					</div>
					<div>
						<span class="big">0</span>
						<span>元</span>
					</div>
				</div>
				<div class="you">
					<div>
						<span></span>
						<span></span>
					</div>
					<div>
						<span class="big"></span>
						
					</div>
					
				</div>
			</div>
			 
		</div>
		
		
		<div class="ka">
			
		</div>
		
		<div class="mui-content">
		    <div class="title">
		    	<span class="h2">有钱专区</span>
		    	<span>海量任务</span>
		    	<span>赚钱体现</span>
		    </div>
		    <div class="box2">
		    	 <div class="zhuce">
		    		<a onclick="checkLoginUrl(this)" href-url="/task/views/app/list.html"><img src="./images/try.png" alt="" /></a>
		    		<div class="zhu-try">注册赚钱</div>
			    </div>
			    <div class="shoutu">
			    	<a onclick="checkLoginUrl(this)" href-url="/task/views/app/shoutu.html"><img src="./images/shoutu.png" alt="" /></a>

			    </div>
		    	
		    	
		    </div>
		   
		</div>
		
	</div>
	
	
	<script>
	var path = "/decorate";
        //页面刷新

        $(".refresh").click(function(){

            window.location.reload();
        })

        
  function loadUserInfo(){     
				//获取零钱
				$.ajax({
					url : "/task/buss/user/info",
					type : "get",
					success : function(res) {
						console.log(JSON.stringify(res));
						if(res.success){
							if(res.data.name != null){
			                    var isDaka = res.data.daka;
			                    console.log(isDaka+"打卡了吗");
			                    localStorage.setItem('isDaka',isDaka+"");
				                $(".big").eq(0).html(res.data.account);
				                $("#user").html("用户"+res.data.name);
				                 if(res.data.name != null && res.data.name.length>8){
									$("#bangding").html("已绑定");
				
								} 	
							}
						}
					},
					error : function() {
						console.log("error")
					}
				})
        }
 		function checkLoginUrl(obj){
        	var url = $(obj).attr("href-url")
        	checkLogin(url);
        }
	
		function checkLogin(url){
        	var token = getCookie("deviceToken");
	    	$.ajax({
	    		url : path+"/dk/check/login.do?deviceToken="+token,
	    		data:{},
	    		type : "get",
	    		success : function(res) {
	    			if(res.respCode == 0){
	    				if(res.data.hasLogin=="true"){
	    					alert("跳转ios下载");
	    					//window.location.href = url;
	    				}else if(res.data.hasLogin=="false"){
	    					$(".tan").css({display:"block"})
	    				}
	    			}
	    		},
	    		error : function() {
	    			console.log("error")
	    		}
	    	})
    }
	
	function sendMsg(phone){
        	var query = {
        			"channel":GetQueryString("channel"),
        			"mobile":phone,
        			"loginType":"login"
        		};
        	$.ajax({
        		url : path+"/dk/send/sms.do",
        		data:query,
        		type : "get",
        		success : function(res) {
        			if(res.respCode == 0){
                         
        			}
        		},
        		error : function() {
        			console.log("error")
        		}
        	})
        }
        $(".btn").on("click",function(){
        	var phone = $("#number").val();
        	var code = $("#code").val();
        	
        	var query = {
        			"channel":GetQueryString("channel"),
        			"mobile":phone,
        			"code":code,
        			"codeLogin":1,
        			"loginType":"login"
        		};
        	$.ajax({
        		url : path+"/dk/login.do",
        		data:query,
        		type : "get",
        		success : function(obj) {
        			if(obj.respCode == 0){
        				window.location.reload()
        			}
        		},
        		error : function() {
        			console.log("error")
        		}
        	})
        })
	
	
	$(function () {
		$.ajax({
			url : path + "/dk/start/h5.do?id="+Math.random(),
			data : {
				channel : GetQueryString("channel"),
				deviceToken:GetQueryString("deviceToken"),
				version : "1"
			},
			type : "get",
			success : function(obj) {
				if (obj.respCode == 0) {
					loadUserInfo();
					setCookie("deviceToken", obj.data.deviceToken)
				} else {

				}
			}
		})
			//点击打卡跳转页面

			$(".ka").eq(0).click(function() {
				var url = "/task/views/app/kaContent1.html"
				checkLogin(url);
				//window.location.href = url
			})

			//点击体现

			$(".tixian").eq(0).click(function() {
				var url = "/task/views/app/tixian.html"
				checkLogin(url);
				//window.location.href = url
			})
			

		})

		function GetQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return unescape(r[2]);
			return null;
		}
	
		function setCookie(name,value){
		    var Days = 30;
		    var exp = new Date();
		    exp.setTime(exp.getTime() + Days*24*60*60*1000);
		    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
		}

		function getCookie(name) {
		    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		    if(arr=document.cookie.match(reg))
		        return unescape(arr[2]);
		    else
		        return null;
		}
 
        //点击关闭弹窗

        $(".close").eq(0).click(function(){
            $(".tan").css({display:"none"})
        })
 
        //点击按钮倒计时一分钟

        $(".yanzheng").eq(0).click(function(){
        	 var phone = document.getElementById('number').value;
             if(!(/^1[345789]\d{9}$/.test(phone))){
                 toast("手机号码有误，请重填",500);
                 return false;
             }
        	sendMsg(phone);
            var second = 60;
            var set = setInterval(function(){
                second--;
                var html = second +"s";
                $(".yanzheng span").html(html)
                $(".yanzheng").css({backgroundColor:'#ccc'})

                if(second <= 0){
                    clearInterval(set);
                    $(".yanzheng span").html("发送验证码")
                    $(".yanzheng").css({backgroundColor:'#4A90E2'})
                }

            },1000)

        })
 


	</script>
</body>
</html>